package com.ruoyi.program.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.program.domain.WxExercise;
import com.ruoyi.program.service.IWxExerciseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 知识库Controller
 *
 * @author ruoyi
 * @date 2025-10-26
 */
@RestController
@RequestMapping("/system/exercise")
public class WxExerciseController extends BaseController
{
    @Autowired
    private IWxExerciseService wxExerciseService;

    /**
     * 查询知识库列表
     */
    @PreAuthorize("@ss.hasPermi('system:exercise:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxExercise wxExercise)
    {
        startPage();
        List<WxExercise> list = wxExerciseService.selectWxExerciseList(wxExercise);
        return getDataTable(list);
    }

    /**
     * 导出知识库列表
     */
    @PreAuthorize("@ss.hasPermi('system:exercise:export')")
    @Log(title = "知识库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxExercise wxExercise)
    {
        List<WxExercise> list = wxExerciseService.selectWxExerciseList(wxExercise);
        ExcelUtil<WxExercise> util = new ExcelUtil<WxExercise>(WxExercise.class);
        util.exportExcel(response, list, "知识库数据");
    }

    /**
     * 获取知识库详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:exercise:query')")
    @GetMapping(value = "/{exerciseId}")
    public AjaxResult getInfo(@PathVariable("exerciseId") Long exerciseId)
    {
        return success(wxExerciseService.selectWxExerciseByExerciseId(exerciseId));
    }

    /**
     * 新增知识库
     */
    @PreAuthorize("@ss.hasPermi('system:exercise:add')")
    @Log(title = "知识库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxExercise wxExercise)
    {
        return toAjax(wxExerciseService.insertWxExercise(wxExercise));
    }

    /**
     * 修改知识库
     */
    @PreAuthorize("@ss.hasPermi('system:exercise:edit')")
    @Log(title = "知识库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxExercise wxExercise)
    {
        return toAjax(wxExerciseService.updateWxExercise(wxExercise));
    }

    /**
     * 删除知识库
     */
    @PreAuthorize("@ss.hasPermi('system:exercise:remove')")
    @Log(title = "知识库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{exerciseIds}")
    public AjaxResult remove(@PathVariable Long[] exerciseIds)
    {
        return toAjax(wxExerciseService.deleteWxExerciseByExerciseIds(exerciseIds));
    }
}
